﻿using Microsoft.AspNetCore.Mvc;
using NewRetail.Application.Components.Platform;
using NewRetail.Application.Components.Platform.Entity;
using NewRetail.Application.Core;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace NewRetail.Api.Controllers
{
    [NewRetailRoute("pos-cash-register")]
    public class PosCashRegisterController : BaseController<PosCashRegister>
    {
        private readonly IPosCashierService posCashierService;
        public PosCashRegisterController(IPosCashierService posCashierService)
        {
            this.posCashierService = posCashierService;
        }

        public override async Task<ResponseEntity<PagedResultDto<PosCashRegister>>> QueryPaging([FromBody] PagingRequestDto dto)
        {
            var data = await base.QueryPaging(dto);

            if (data.Data?.Items?.Any() ?? false)
            {
                data.Data.Items = await this.posCashierService.AttachWarehouseForCashierRegister(data.Data.Items.ToArray());
            }

            return data;
        }
    }
}
